﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using YArchitech.Controls;
using YArchitech.DataModel;
using YArchitech.LIB;

namespace YArchitech.Plumbing
{
	public partial class Form3DTextMark : System.Windows.Forms.Form
	{
		public Form3DTextMark()
		{
			this.InitializeComponent();
			new YJKProcessTools().ShowInTaskbarChange(this);
			base.Icon = Resource.YArchitechIcon;
		}

		private void hyTextBox1_TextChanged(object sender, EventArgs e)
		{
		}

		private void Form3DTextMark_Load(object sender, EventArgs e)
		{
			string[] textMarkText = this.userSetting.GetTextMarkText();
			try
			{
				foreach (string text in textMarkText[0].Split(new char[]
				{
					'.'
				}))
				{
					if (text != "")
					{
						this.comboBoxText.Items.Add(text);
						this.list.Add(text);
					}
				}
				this.comboBoxText.SelectedItem = this.list.ElementAt(0);
				this.hyTextBox45Length.Text = textMarkText[1];
				this.hyTextBox90Length.Text = textMarkText[2];
			}
			catch
			{
				this.comboBoxText.Items.Add("脸");
				this.list.Add("脸");
				this.comboBoxText.Items.Add("拖");
				this.list.Add("拖");
				this.comboBoxText.SelectedItem = this.comboBoxText.Items[0];
				this.hyTextBox45Length.Text = "1000";
				this.hyTextBox90Length.Text = "1500";
			}
			if (string.IsNullOrEmpty(this.comboBoxText.Text) && this.comboBoxText.Items != null && this.comboBoxText.Items.Count > 0)
			{
				this.comboBoxText.SelectedItem = this.comboBoxText.Items[0];
			}
		}

		private void Form3DTextMark_Deactivate(object sender, EventArgs e)
		{
			if (this.comboBoxText.Text.Trim().Length >= 1)
			{
				this.comboBoxText.Text = this.comboBoxText.Text.Trim();
				this.comboBoxText.Text = this.comboBoxText.Text.Trim().ElementAt(0).ToString();
			}
			if (this.comboBoxText.Text.Trim() != "" && this.hyTextBox45Length.Text != "" && this.hyTextBox90Length.Text != "")
			{
				string[] array = new string[3];
				if (!this.list.Contains(this.comboBoxText.Text.Trim().ToString()))
				{
					this.comboBoxText.Items.Add(this.comboBoxText.Text.Trim().ToString());
					this.list.Insert(0, this.comboBoxText.Text.Trim().ToString());
				}
				string text = "";
				if (this.list.ElementAt(0) != this.comboBoxText.Text.Trim().ToString() && this.list.Contains(this.comboBoxText.Text.Trim().ToString()))
				{
					this.list.Remove(this.comboBoxText.Text.Trim().ToString());
					this.list.Insert(0, this.comboBoxText.Text.Trim().ToString());
				}
				foreach (string str in this.list)
				{
					text = text + str + ".";
				}
				text.Remove(text.Count<char>() - 1);
				array[0] = text;
				array[1] = this.hyTextBox45Length.Text;
				array[2] = this.hyTextBox90Length.Text;
				this.userSetting.WriteTextMarkText(array);
				return;
			}
			YJKMessageBox.Show("请确保输入不为空！");
		}

		private void comboBoxText_TextChanged(object sender, EventArgs e)
		{
			if (this.comboBoxText.Text.Trim().Length >= 1)
			{
				this.comboBoxText.Text = this.comboBoxText.Text.Trim();
				this.comboBoxText.Text = this.comboBoxText.Text.Trim().ElementAt(0).ToString();
			}
		}

		private HVACUserSetting userSetting = new HVACUserSetting();

		private List<string> list = new List<string>();
	}
}
